// Class include
#include "CArduinoClient.hpp"

// System includes

// Other includes
#include "CTrace.hpp"

CArduinoClient::CArduinoClient()
: CObserver()
, mpSocketClient(0)
{

}

void CArduinoClient::init(CSocketClient* pSocketClient)
{
   if (0 != pSocketClient)
   {
      mpSocketClient = pSocketClient;
   }
   else
   {
      TRC_ERROR("SocketClient pointer is NULL");
   }
}

void CArduinoClient::onArduinoOnline(const CCommand& cmd)
{
   CCommand cmdOut(COMMAND_SOURCE_SOCKET, COMMAND_PC_ENGINE_BACKWARD, 1);
   mpSocketClient->sendCommand(cmdOut);
}

void CArduinoClient::onButtonSw1(const CCommand& cmd)
{
   CCommand cmdOut(COMMAND_SOURCE_SOCKET, COMMAND_PC_ENGINE_FORWARD, 1);
   mpSocketClient->sendCommand(cmdOut);
}

void CArduinoClient::handleEvent(const CCommand& cmd)
{
   TRC_DEBUG("Incoming command");
   switch (cmd.getType())
   {
      case COMMAND_ARDUINO_ONLINE:
      {
         onArduinoOnline(cmd);
         break;
      }
      case COMMAND_ARDUINO_BTNSW_1:
      {
         onButtonSw1(cmd);
         break;
      }
      default:
      {
         TRC_WARNING("Got unknown command = %s. Do not know how to handle it.", toString(cmd.getType()));
      }
   }
}

void CArduinoClient::start()
{
   TRC_DEBUG("Started Dummy Arduino Client");
}